<% layout('/layouts/default.html', {title: '会员流水账', libs: ['dataGrid']}){ %>
<div class="main-content">
    <div class="box box-main">
        <div class="box-header">
            <div class="box-title">
                <i class="fa fa-list-alt"></i> (${startTime}至${endTime})${text('所有会员流水账报表')}
            </div>
            <div class="box-tools pull-right">
                <% if(hasRoles('1000')){ %>
                <a href="javascript:void(0);" onclick="goBackRreTab();" class="btn btn-default btnTool" title="${text('报表管理')}"><i class="fa fa-plus"></i> ${text('返回上一页')}</a>
                <% } %>
                <a href="#" class="btn btn-default" id="btnSearch" title="${text('查询')}"><i class="fa fa-filter"></i> ${text('查询')}</a>
                <% if(hasPermi('vip:member:edit')){ %>
                <a href="${ctx}/vip/member/form" class="btn btn-default btnTool" title="${text('新增会员')}"><i class="fa fa-plus"></i> ${text('新增')}</a>
                <% } %>
                <div class="btn-group">
                    <a href="javascript:" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                        <i class="fa fa-navicon"></i> <span class="caret"></span>
                    </a>
                    <ul class="dropdown-menu">
                        <li><a href="javascript:" id="btnExport"><i class="glyphicon glyphicon-export"></i> 导出</a></li>
                    </ul>
                </div>
            </div>
        </div>
        <div class="box-body">
            <#form:form id="searchForm" model="${memberRecord}" action="${ctx}/vip/record/memberRecordData?userCode=${userCode}" method="post" class="form-inline hide"
            data-page-no="${parameter.pageNo}" data-page-size="${parameter.pageSize}" data-order-by="${parameter.orderBy}">
            <div class="form-group">
                <label class="control-label">起始时间：</label>
                <div class="control-inline">
                    <input name="startTime" readonly="readonly" value="${startTime}" maxlength="20" class="form-control Wdate-date"
                    dataFormat="date" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false,onpicked:function(){createDate_lte.click()}});"/>
                    &nbsp;--&nbsp;
                    <input name="endTime" value="${endTime}" readonly="readonly" maxlength="20" class="form-control Wdate-date"
                    dataFormat="date" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false});"/>
                </div>
            </div>
            <div class="form-group">
                <button type="submit" class="btn btn-primary btn-sm">${text('查询')}</button>
                <button type="reset" class="btn btn-default btn-sm">${text('重置')}</button>
            </div>
        </#form:form>
        <div class="box-title" id="countTitle" style="padding:4px;text-align:center;font-size:20px;">
        </div>
        <table id="dataGrid"></table>
        <div id="dataGridPage"></div>
    </div>
</div>
</div>
<% } %>
<script>
    // 初始化DataGrid对象
    $('#dataGrid').dataGrid({
        searchForm: $("#searchForm"),
        columnModel: [
            {header:'${text('会员姓名')}', name:'memberName', index:'a.memberName', width:150, align:"center", frozen:true, formatter: function(val, obj, row, act){
                    return '<a href="${ctx}/vip/record/memberPersonRecord?memberId='+row.memberId+'&startTime=${startTime}&endTime=${endTime}'+
                      '" class="btnList" data-title="${text('会员个人流水账')}">'+(val||row.id)+'</a>';
                }},
            {header:'${text('所属代理')}', name:'agentName', index:'a.agentName', width:150, align:"center"},
            {header:'${text('出货')}', name:'out', index:'a.out', width:150, align:"center", formatter: function(val, obj, row, act){
                    return formatNumber(val); // 数值类型格式化 (原始数值, 小数位数, 是否千分位, 默认值，金额情况下设置0.00);
                }},
            {header:'${text('入货')}', name:'in', index:'a.in', width:150, align:"center", formatter: function(val, obj, row, act){
                    return formatNumber(val); // 数值类型格式化 (原始数值, 小数位数, 是否千分位, 默认值，金额情况下设置0.00);
                }},
            {header:'${text('积分')}', name:'points', index:'a.points', width:150, align:"center", formatter: function(val, obj, row, act){
                    return formatNumber(val); // 数值类型格式化 (原始数值, 小数位数, 是否千分位, 默认值，金额情况下设置0.00);
                }},
            {header:'${text('总充值')}', name:'rechargeTotal', index:'a.rechargeTotal', width:150, align:"center", formatter: function(val, obj, row, act){
                    return formatNumber(val); // 数值类型格式化 (原始数值, 小数位数, 是否千分位, 默认值，金额情况下设置0.00);
                }},
            {header:'${text('总支出')}', name:'payTotal', index:'a.payTotal', width:150, align:"center", formatter: function(val, obj, row, act){
                    return formatNumber(val); // 数值类型格式化 (原始数值, 小数位数, 是否千分位, 默认值，金额情况下设置0.00);
                }}
        ],
        // 加载成功后执行事件
        ajaxSuccess: function(data){
            buildCount(data.otherData)
        }
    });

    $('#btnExport').click(function(){
        js.ajaxSubmitForm($('#searchForm'), {
            url:'${ctx}/vip/record/memberRecordData?exportCode=1',
            downloadFile:true
        });
    });
    //统计数据标题
    function buildCount(countData){
        if(countData == undefined){
            $('#countTitle').html("统计数据为空");
            return;
        }
        var inTitle ="总入货:"+formatNumber(countData.in)+"&nbsp&nbsp&nbsp";
        var outTitle ="总出货:"+formatNumber(countData.out)+"&nbsp&nbsp&nbsp";
        var rechargeTitle ="总充值:"+formatNumber(countData.rechargeTotal)+"&nbsp&nbsp&nbsp";
        var pointsTitle ="总积分:"+formatNumber(countData.points)+"&nbsp&nbsp&nbsp";
        var payTitle = "总支出:"+formatNumber(countData.payTotal)+"&nbsp&nbsp&nbsp";
        $('#countTitle').html(outTitle + inTitle + pointsTitle + rechargeTitle + payTitle);
    }
</script>